﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Lyon.WinForm
{
    /// <summary>
    /// 重复动作框
    /// </summary>
    public class RepeatBox
    {
        /// <summary>
        /// 显示。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="owner"></param>
        /// <param name="title"></param>
        /// <param name="collection"></param>
        /// <param name="action"></param>
        /// <param name="finished"></param>
        /// <param name="abort"></param>
        static public void Show<T>(IWin32Window owner, string title, IEnumerable<T> collection, Action<T> action, Callback finished, Callback abort)
        {
            RepeatForm repeatForm = new RepeatForm(finished, abort);
            repeatForm.Context = title;
            repeatForm.Text = title;
            repeatForm.ForEach<T>(collection, action);
            repeatForm.Show(owner);
        }
        /// <summary>
        /// 显示。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="owner"></param>
        /// <param name="title"></param>
        /// <param name="collection"></param>
        /// <param name="action"></param>
        /// <param name="finished"></param>
        /// <param name="abort"></param>
        static public void ShowDialog<T>(IWin32Window owner, string title, IEnumerable<T> collection, Action<T> action, Callback finished, Callback abort)
        {
            RepeatForm repeatForm = new RepeatForm(finished, abort);
            repeatForm.Context = title;
            repeatForm.Text = title;
            repeatForm.Load += new EventHandler(delegate(object sender, EventArgs e)
            {
                repeatForm.ForEach<T>(collection, action);
            });
            repeatForm.ShowDialog(owner);
        }
    }
}
